<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">列表</h3></div>
            <div class="panel-body">
                <form action="" id="search-form" class="search-form">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12 col-md-4  add-space">
                                <div class="input-group input-group-md">
                                    <span class="input-group-addon">Shipmentid</span>
                                    <input type="text" name="shipmentid" class="form-control">
                                </div>
                            </div>
                            <!--<div class="col-sm-12 col-md-4  add-space">
                                <div class="input-group input-group-md">
                                    <span class="input-group-addon">拣货编码</span>
                                    <select class="chosen-select form-control" tabindex="-1" name="orde"
                                            data-name-group="common">
                                        <option value="" class="empty-opt">-- 请选择 --</option>
                                        <option value="OVERSEA">OVERSEA</option>
                                        <option value="OLDERP">OLDERP</option>
                                    </select>
                                </div>
                            </div>-->
                            <div class="col-md-2 add-space">
                                <input class="btn btn-primary jsSearchBtn" type="button" value="搜索">
                            </div>
                        </div>
                    </div>
                </form>
                <hr>
                <div class="detail_content">

                </div>
                <include file="Inbound@Inboundshipmentplan/plan_detail"/>
                <div class="alert alert-info top20" role="alert">
                    <p>*注意所有站点单箱超过15KG,都需要贴超重标签，所有站点单箱不能少于10KG。</p>
                </div>
                <hr>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="isWeight" value="1">不限制重量
                    </label>
                    <label>
                        <input type="checkbox" name="isCheck" value="1">不限制体积
                    </label>
                </div>

                <div class="row">

                    <div class="col-md-6">
                        <h5>非退税</h5>

                        <p class="m10" style="float: left;">
                            <input name="not_tax_package_quantity" type="text" class="form-control w120"
                                   placeholder="箱数"
                                   required="required">
                            <button type="button" class="btn is_not_tax">确定</button>
                        </p>
                        <p class="m10" style="float: left; margin-left:5px;">
                            <input type="number" class="form-control w50" value="1" name="number"/>
                            <a href="javascript:void(0)" class="copy_row">复制</a>
                        </p>
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>重量<span class="fred">(kg)*</span></th>
                                <th>长(cm)*宽(cm)*高(cm</th>
                                <th nowrap="">操作</th>
                            </tr>
                            </thead>
                            <tbody id="addtr">

                            </tbody>
                        </table>
                        <!--<a id="xinzen" href="javascript:void(0)" onclick="addConsignerAddress()"> 新增一行 </a>-->
                    </div>
                    <div class="col-md-6">
                        <h5>退税</h5>

                        <p class="m10" style="float: left;">
                            <input name="tax_package_quantity" type="text" class="form-control w120" placeholder="箱数"
                                   required="required">
                            <button type="button" class="btn is_tax">确定</button>
                        </p>
                        <p class="m10" style="float: left; margin-left:5px;">
                            <a href="javascript:void(0)" class="copy_row">复制</a>
                            <input type="number" class="form-control w50" value="1"/>
                        </p>
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th> 重量<span class="fred">(kg)*</span></th>
                                <th> 长(cm)*宽(cm)*高(cm</th>
                                <th nowrap=""> 操作</th>
                            </tr>
                            </thead>
                            <tbody id="addtr3">

                            </tbody>
                        </table>
                        <!--<a id="xinzen1" href="javascript:void(0)" onclick="addConsignerAddress()"> 新增一行 </a>-->

                    </div>
                    <div class="col-md-2 col-md-offset-8">
                        <div class="form-group">
                            <button type="button" class="btn btn-primary ajax-submit submit_order">提交</button>
                        </div>
                    </div>

                </div>


            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script>
$(function () {
    $("input[name='shipmentid']").val("<?php  echo $_GET['shipmentid'];?>");
    document.onkeypress = function(){
        if(event.keyCode == 13) {
            return false;
        }
    }

    $('select.chosen-select').chosen({
        no_results_text: '没有找到',    // 当检索时没有找到匹配项时显示的提示文本
        disable_search_threshold: 2, // 10 个以下的选择项则不显示检索框
        search_contains: true         // 从任意位置开始检索
    });
});

$(".submit_order").click(function(){
    Prepackage.createNew().submit_page_data();
    $(this).attr("disabled", true);
});

$(document).on("click", ".addsku1", function(){
    var aa = $(this).html();
    var arr = aa.split("<br>")
    row_obj = this;

    layer.open({
        type: 2,
        title: '新增sku',
        shadeClose: true, //点击遮罩关闭层
        area: ['800px' , '440px'],
        content: '__URL__/addskuinfo',
        success: function (obj) {
            var aaa = arr;
            var addhtml = '<tr class=""><td>1</td><td><select name="sku_select"><option value=""></option></select></td><td><input name="sku_quantity" type="text" class="form-control" placeholder="请输入数量" required="required"></td><td><a href="#" class="delete_row">删除</a></td></tr>';
            if(arr.length>=2){
                for(i=1;i<arr.length;i++){
                    var num = i+1;
                    addhtml += '<tr class=""><td>'+num+'</td><td><select name="sku_select"><option value=""></option></select></td><td><input name="sku_quantity" type="text" class="form-control" placeholder="请输入数量" required="required"></td><td><a href="#" class="delete_row">删除</a></td></tr>';
                }
            }
            body = $($('iframe', obj).get(0).contentWindow.document.body);
            $("#addtr2", body).html(addhtml);
            $("select[name=sku_select]", body).html($("input[name=sku_list_not_tax]").val());
            $("select[name=sku_select_1]", body).html($("input[name=sku_list_not_tax]").val());
//            $("input[name=sku_quantity]", body).val(0);
            $("select[name=sku_select]", body).each(function(i){
                $(this).children('option').each(function () {
                    if($.trim(aaa[0])=='录入sku'){
                        return true;
                    }else{

                        if($.trim($(this).text()) == $.trim(aaa[i].substring(0,aaa[i].indexOf(":")))){
                            $(this).attr('selected',true);
                        }
                    }
                });

            });
            $("input[name=sku_quantity]", body).each(function(i){
                if(i<aaa.length){
                    if($.trim(aaa[0])=='录入sku'){
                        $(this).val(0);
                    }else{
                        $(this).val(aaa[i].substring(aaa[i].indexOf(":")+1));
                    }

                }

            });
            body.on("click", ".add_row", function(){
                $("#addtr2",body).append($("#addtr_2",body).html());
            });

            body.on("click", ".confirm_row", function(){
                var i = 0;
                var detail = '';
                var flag = false;
                $("#addtr2",body).find('tr').find('td').each(function(){

                    if($(this).find('select').attr('name') == 'sku_select' || $(this).find('select').attr('name') == 'sku_select_1')
                    {
                        if(detail.indexOf($(this).find('select').val()) != -1)
                        {
                            alert($(this).find('select').val()+"存在条数过多");
                            flag = true;
                            return ;
                        }
                        detail += detail == ''? $(this).find('select').val()+' : ' : "<br />"+$(this).find('select').val()+' : ';

                    }else if($(this).find('input').attr('name') == 'sku_quantity')
                    {
                        detail += $(this).find('input').val();
                    }
                });
                if(flag)
                    return;
                $(row_obj).html(detail);
                parent.layer.closeAll();
            });

            body.on('click','.delete_row',function(){
                $(this).parent('td').parent('tr').remove();
            })
        }
    });
});

var body;
//重量限制
$(document).on("blur",".weight",function () {
    if(!$("input:checkbox[name='isWeight']").is(':checked')) {
        var site = $.trim($("input[name='site']").val()),
            weight = eval($(this).val());
        if (weight < 10) {
            alert('所有站点单箱不能少于10KG');
            $(this).val('');
        }
        if (site == 'US' || site == 'CA') {
            if (weight >= 22.5) {
                alert(site + '站点单箱必须少于22.5KG');
                $(this).val('');
            }
        } else {
            if (weight >= 30) {
                alert('其他站点单箱必须少于30KG');
                $(this).val('');
            }
        }
    }
});
//长度限制
$(document).on("blur",".length",function () {
    if(!$("input:checkbox[name='isCheck']").is(':checked')) {
        var site = $.trim($("input[name='site']").val()),
            length = eval($(this).val()),
            w = eval($(this).siblings('.width').val()),
            h = eval($(this).siblings('.height').val());
        if (site == 'US' || site == 'CA' || site == 'IT') {
            if (length >= 63.5) {
                alert(site + '站点最长边必须少于63.5CM');
                $(this).val('');
            }
        } else if (site == 'JP') {
            if (length >= 60) {
                alert(site + '站点最长边必须少于60CM');
                $(this).val('');
            } else if (length >= 50) {
                if (w >= 50 || h >= 50) {
                    alert(site + '站点只允许一边大于50CM');
                    $(this).val('');
                }
            } else {
                if (w >= 50) {
                    if (h >= 50) {
                        alert(site + '站点只允许一边大于50CM');
                        $(this).val('');
                    }
                }
            }
        } else {
            if (length >= 150) {
                alert(site + '站点最长边必须少于150CM');
                $(this).val('');
            } else {
                if (length > w && length > h) {
                    if (length + w + w + h + h > 300) {
                        alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                        $(this).val('');
                    }
                } else {
                    if (w > h) {
                        if (w + length + length + h + h > 300) {
                            alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                            $(this).val('');
                        }
                    } else {
                        if (w + w + length + length + h > 300) {
                            alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                            $(this).val('');
                        }
                    }
                }
            }
        }
    }
});
//宽度限制
$(document).on("blur",".width",function () {
    if(!$("input:checkbox[name='isCheck']").is(':checked')) {
        var site = $.trim($("input[name='site']").val()),
            width = eval($(this).val()),
            l = eval($(this).siblings('.length').val()),
            h = eval($(this).siblings('.height').val());
        if (site == 'US' || site == 'CA' || site == 'IT') {
            if (width >= 63.5) {
                alert(site + '站点最长边必须少于63.5CM');
                $(this).val('');
            }
        } else if (site == 'JP') {
            if (width >= 60) {
                alert(site + '站点最长边必须少于60CM');
                $(this).val('');
            } else if (width >= 50) {
                if (l >= 50 || h >= 50) {
                    alert(site + '站点只允许一边大于50CM');
                    $(this).val('');
                }
            } else {
                if (l >= 50) {
                    if (h >= 50) {
                        alert(site + '站点只允许一边大于50CM');
                        $(this).val('');
                    }
                }
            }
        } else {
            if (width >= 150) {
                alert(site + '站点最长边必须少于150CM');
                $(this).val('');
            } else {
                if (width > l && width > h) {
                    if (width + l + l + h + h > 300) {
                        alert(site + '最长边加上其他两边的两倍的总和不能大于300CM');
                        $(this).val('');
                    }
                } else {
                    if (l > h) {
                        if (width + width + l + h + h > 300) {
                            alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                            $(this).val('');
                        }
                    } else {
                        if (width + width + l + l + h > 300) {
                            alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                            $(this).val('');
                        }
                    }
                }
            }
        }
    }
});
//高度限制
$(document).on("blur",".height",function () {
    if(!$("input:checkbox[name='isCheck']").is(':checked')) {
        var site = $.trim($("input[name='site']").val()),
            height = eval($(this).val()),
            l = eval($(this).siblings('.length').val()),
            w = eval($(this).siblings('.width').val());
        if (site == 'US' || site == 'CA' || site == 'IT') {
            if (height >= 63.5) {
                alert(site + '站点最长边必须少于63.5CM');
                $(this).val('');
            }
        } else if (site == 'JP') {
            if (height >= 60) {
                alert(site + '站点最长边必须少于60CM');
                $(this).val('');
            } else if (height >= 50) {
                if (l >= 50 || w >= 50) {
                    alert(site + '站点只允许一边大于50CM');
                    $(this).val('');
                }
            } else {
                if (l >= 50) {
                    if (w >= 50) {
                        alert(site + '站点只允许一边大于50CM');
                        $(this).val('');
                    }
                }
            }
        } else {
            if (height >= 150) {
                alert(site + '站点最长边必须少于150CM');
                $(this).val('');
            } else {
                if (height > l && height > w) {
                    if (height + l + l + w + w > 300) {
                        alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                        $(this).val('');
                    }
                } else {
                    if (l > w) {
                        if (height + height + l + w + w > 300) {
                            alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                            $(this).val('');
                        }
                    } else {
                        if (height + height + l + l + w > 300) {
                            alert(site + '站点最长边加上其他两边的两倍的总和不能大于300CM');
                            $(this).val('');
                        }
                    }
                }
            }
        }
    }
});

$(document).on("click", ".addsku2", function(){

    var aa = $(this).html();
    var arr = aa.split("<br>")
//    alert(arr.length)
//    for(i=0;i<arr.length;i++){
//        num = arr[i].indexOf(":");
//        alert(arr[i].substring(num+1));
//    }
    row_obj = this;
    layer.open({
        type: 2,
        title: '新增sku',
        shadeClose: true, //点击遮罩关闭层
        area: ['800px' , '440px'],
        content: '__URL__/addskuinfo',
        success: function (obj) {
            var aaa = arr;
            var addhtml = '<tr class=""><td>1</td><td><select name="sku_select"><option value=""></option></select></td><td><input name="sku_quantity" type="text" class="form-control" placeholder="请输入数量" required="required"></td><td><a href="#" class="delete_row">删除</a></td></tr>';
            if(arr.length>=2){
                for(i=1;i<arr.length;i++){
                    var num = i+1;
                    addhtml += '<tr class=""><td>'+num+'</td><td><select name="sku_select"><option value=""></option></select></td><td><input name="sku_quantity" type="text" class="form-control" placeholder="请输入数量" required="required"></td><td><a href="#" class="delete_row">删除</a></td></tr>';
                }
            }
            body = $($('iframe', obj).get(0).contentWindow.document.body);
            $("#addtr2", body).html(addhtml);
            $("select[name=sku_select]", body).html($("input[name=sku_list_tax]").val());
            $("select[name=sku_select_1]", body).html($("input[name=sku_list_tax]").val());

            $("select[name=sku_select]", body).each(function(i){
                $(this).children('option').each(function () {
                    if($.trim(aaa[0])=='录入sku'){
                        return true;
                    }else{

                        if($.trim($(this).text()) == $.trim(aaa[i].substring(0,aaa[i].indexOf(":")))){
                            $(this).attr('selected',true);
                        }
                    }
                });

            });

            $("select[name=sku_select_1]", body).each(function(i){
                if(i<aaa.length){
                    if($.trim(aaa[0])=='录入sku'){
                        $(this).val($("input[name=sku_list_tax]").val());
                    }else{
                        $(this).val(aaa[i].substring(aaa[i].indexOf(":")+1));
                    }

                }

            });


            $("input[name=sku_quantity]", body).each(function(i){

                if(i<aaa.length){
                    if($.trim(aaa[0])=='录入sku'){
                        $(this).val(0);
                    }else{
                        $(this).val(aaa[i].substring(aaa[i].indexOf(":")+1));
                    }

                }

            });
               // $("input[name=sku_quantity]", body).val(arr[i].substring(arr[i].indexOf(":")+1));

            //$("input[name=sku_quantity]", body).val(0);

            body.on("click", ".add_row", function(){
                $("#addtr2",body).append($("#addtr_2",body).html());
            });

            body.on("click", ".confirm_row", function(){
                var flag = false;
                var detail = '';
                $("#addtr2",body).find('tr').find('td').each(function(){
                    if($(this).find('select').attr('name') == 'sku_select' || $(this).find('select').attr('name') == 'sku_select_1')
                    {
                        if(detail.indexOf($(this).find('select').val()) != -1)
                        {
                            alert($(this).find('select').val()+"存在条数过多");
                            flag = true;
                            return ;
                        }
                        detail += detail == ''? $(this).find('select').val()+' : ' : "<br />"+$(this).find('select').val()+' : ';
                    }else if($(this).find('input').attr('name') == 'sku_quantity')
                    {
                        detail += $(this).find('input').val();
                    }
                });

                if(flag)
                    return;
                $(row_obj).html(detail);
                parent.layer.closeAll();
            });

            body.on('click','.delete_row',function(){
                $(this).parent('td').parent('tr').remove();
            })
        }
    });
});

$(".copy_row").click(function(){
    var number = $(this).parent('p').find('input').val();
    var html   = $('input:radio[name=is_not_tax_radio]:checked').parent('td').parent('tr').html();
    var obj    = $('input:radio[name=is_not_tax_radio]:checked').parent('td').parent('tr');

    var length   = '';
    var width    = '';
    var height   = '';
    var weight   = '';
    var sku_detail = '';

    $(obj).find('td').each(function(){

        if($(this).find('input').attr('class') == 'form-control w50 weight')
        {
            weight = $(this).find('input').val();
        }else if($(this).find('input').attr('class') == 'form-control w50 length'){
            length = $(this).find('input').val();
            width  = $(this).find('input').eq(1).val();
            height = $(this).find('input').eq(2).val();
        }else if($(this).find('a').attr('class') == 'is_not_tax_sku addsku1' || $(this).find('a').attr('class') == 'is_not_tax_sku addsku2'){
            sku_detail = $(this).find('a').html();
        }
    });

    for(var i = 0; i < number;i++)
    {
        obj = obj.next('tr');

        $(obj).find('td').each(function(){
            if($(this).find('input').attr('class') == 'form-control w50 weight')
            {
                $(this).find('input').val(weight);
            }else if($(this).find('input').attr('class') == 'form-control w50 length'){
                $(this).find('input').val(length);
                $(this).find('input').eq(1).val(width);
                $(this).find('input').eq(2).val(height);
            }else if($(this).find('a').attr('class') == 'is_not_tax_sku addsku1' || $(this).find('a').attr('class') == 'is_not_tax_sku addsku2'){
                $(this).find('a').html(sku_detail);
            }
        });
    }
});

var Checkqualitydetails = {

    createNew: function () {

        var checkqualitydetails = {};

        checkqualitydetails.str = '';

        checkqualitydetails.flag = true;

        checkqualitydetails.page_data = new Array();

        checkqualitydetails.page_data_tax = new Array();

        /*checkqualitydetails.get_prepackage_details = function () {
            if ($("input[name=recieve_detail_id]").val() == '') {
                layer.msg('请输入入库预报详情单号', {offset: 250});
                return;
            }

            $.ajax({
                type: "GET",

                url: 'Transitwms/Prepackage/other_prepackage',

                data: {otherstock_detail_id: $("input[name=recieve_detail_id]").val()},

                dataType: "json",

                success: function (data) {


                }
            });
        }*/

        /*checkqualitydetails.get_check_quality_details = function () {

            if ($("input[name=recieve_detail_id]").val() == '') {

                layer.msg('请输入收货明细单号', {offset: 250});
                return;
            }

            $.ajax({
                type: "GET",

                url: 'Transitwms/prepackage/get_check_quality_details',

                data: {recieve_detail_id: $("input[name=recieve_detail_id]").val()},

                dataType: "json",

                success: function (data) {

                }
            });
        }*/


        checkqualitydetails.get_page_data = function () {

            var i = 0;
            var quantity = 0;

            $("#addtr tr").each(function (index, data) {
                checkqualitydetails.page_data[i] = {};
                $(this).find('td').each(function(){
                    if($(this).find('input').attr('class') == 'form-control w50 weight')
                    {
                        checkqualitydetails.page_data[i].inbound_shipment_plan_id = $("input[name=inbound_shipment_plan_id]").val();
                        checkqualitydetails.page_data[i].export_tax_rebate = 0;
                        checkqualitydetails.page_data[i].weight = $(this).find('input').eq(0).val();

                        if (checkqualitydetails.page_data[i].weight == '')
                        {
                            checkqualitydetails.flag = false;
                            popup.success("请检查非退税第"+(++i) +"行重量是否填写完整");
                            return false;
                        }
                    }else if($(this).find('input').attr('class') == 'form-control w50 length'){

                        checkqualitydetails.page_data[i].length = $(this).find('input').eq(0).val();
//                        alert(checkqualitydetails.page_data[i].length);
                        checkqualitydetails.page_data[i].width  = $(this).find('input').eq(1).val();
                        checkqualitydetails.page_data[i].height = $(this).find('input').eq(2).val();
                        if (checkqualitydetails.page_data[i].length == ''
                                ||checkqualitydetails.page_data[i].width ==''
                                ||checkqualitydetails.page_data[i].height =='')
                        {
                            checkqualitydetails.flag = false;
                            popup.success("请检查非退税第"+(++i) +"行长宽高是否填写完整");
                            return false;
                        }
                    }else if($(this).find('a').attr('class') == 'is_not_tax_sku addsku1'){
                        checkqualitydetails.page_data[i].sku_detail = $(this).find('a').html();
                        if ($(this).find('a').html() == '录入sku')
                        {
                            checkqualitydetails.flag = false;
                            popup.success("请检查非退税sku第"+(++i) +"行是否填写完整");
                            return false;
                        }
                    }
                    //alert($(this).html());
                });

                i++;
                /*if ($("input[name=length_" + index + "]").val() == '' || $("input[name=quantity_" + index + "]").val() == '' ||
                        $("input[name=width_" + index + "]").val() == '' || $("input[name=height_" + index + "]").val() == '' ||
                        $("input[name=weight_" + index + "]").val() == '') {
                    checkqualitydetails.flag = false;
                    popup.success("请检查长宽高重量是否填写完整");
                    return;
                }
                checkqualitydetails.page_data[i] = {'recieve_detail_id': $("input[name=recieve_detail_id]").val(), 'sku': $("input[name=sku]").val(), 'weight': $("input[name=weight_" + index + "]").val(),
                    'purchaseorder_id': $("input[name=purchaseorder_id]").val(), 'transport_mode': $("input[name=transport_mode]").attr('data-id'), 'trans_fee': $("input[name=trans_fee]").val(),
                    'sku_name': $("input[name=sku_name]").val(), 'qualified_quantity': $("input[name=quantity_" + index + "]").val(), 'po_sn': $("input[name=po_sn]").val(),
                    'length': $("input[name=length_" + index + "]").val(), 'width': $("input[name=width_" + index + "]").val(), 'height': $("input[name=height_" + index + "]").val(), 'single_price': $("input[name=single_price]").val(),
                    'sku_standard': $("input[name=length_" + index + "]").val() + '*' + $("input[name=width_" + index + "]").val() + '*' + $("input[name=height_" + index + "]").val(),
                    'group': $("input[name=group]").val(), 'store': $("input[name=store]").attr('data-id'), 'check_detail_id': $("input[name=check_detail_id]").val(),
                    'transfer_hopper_id': $("input[name=transfer_hopper_id]").val(), 'enterprise_dominant': $("input[name=enterprise_dominant]").val(),
                    'packing_date': $("input[name=packing_date]").val(), 'packing_userid': $("select[name=packing_userid]").val(), 'remark': $("input[name=remark]").val(), 'type': $("select[name=type]").val(), 'status': 10,
                    'sku_cname': $("input[name=item]").val(), 'hs_code': $("input[name=hs_code]").val(), 'export_tax_rebate': $("input[name=export_tax_rebate]").val(), 'single_price': $("input[name=single_price]").val(),
                    'sku_quantity': $("input[name=quantity_" + index + "]").val(), 'tax_price': $("input[name=tax_price]").val()
                };
                quantity += parseInt($("input[name=quantity_" + index + "]").val());
                i++;*/
            });

            $("#addtr3 tr").each(function(){
                checkqualitydetails.page_data[i] = {};
                $(this).find('td').each(function(){
                    console.log($(this).find('input').attr('class'));
                    if($(this).find('input').attr('class') == 'form-control w50 weight')
                    {
                        checkqualitydetails.page_data[i].inbound_shipment_plan_id = $("input[name=inbound_shipment_plan_id]").val();
                        checkqualitydetails.page_data[i].export_tax_rebate = 1;
                        checkqualitydetails.page_data[i].weight = $(this).find('input').eq(0).val();
                        if (checkqualitydetails.page_data[i].weight == '')
                        {
                            checkqualitydetails.flag = false;
                            popup.success("请检查退税重量是否填写完整");
                            return false;
                        }

                    }else if($(this).find('input').attr('class') == 'form-control w50 length'){
                        checkqualitydetails.page_data[i].length = $(this).find('input').eq(0).val();
                        checkqualitydetails.page_data[i].width  = $(this).find('input').eq(1).val();
                        checkqualitydetails.page_data[i].height = $(this).find('input').eq(2).val();
                        if (checkqualitydetails.page_data[i].length == ''
                                ||checkqualitydetails.page_data[i].width ==''
                                ||checkqualitydetails.page_data[i].height =='')
                        {
                            checkqualitydetails.flag = false;
                            popup.success("请检查退税长宽高是否填写完整");
                            return false;
                        }
                    }else if($(this).find('a').attr('class') == 'is_not_tax_sku addsku2'){
                        checkqualitydetails.page_data[i].sku_detail = $(this).find('a').html();
                        if ($(this).find('a').html() == '录入sku')
                        {
                            checkqualitydetails.flag = false;
                            popup.success("请检查退税sku是否填写完整");
                            return false;
                        }
                    }
                });
                i++;
            });
            //alert(checkqualitydetails.page_data.length);
            if(checkqualitydetails.page_data.length == 0)
            {
                popup.success("请填写装箱信息");
            }
        }

        return checkqualitydetails;
    }

};

var Prepackage = {

    createNew: function () {
        var prepackage = Checkqualitydetails.createNew();

        prepackage.submit_page_data = function () {

            prepackage.get_page_data();
            if ($("input[name=sku]").val() == '') {
                layer.msg('请确认质检单是否存在', {offset: 250});
                return;
            }

            if (!prepackage.flag)
                return;
            prepackage.ajax_request(prepackage.page_data,
                    'Inbound/Inboundshipmentplan/create_package_box', Prepackage.createNew().get_create_package_box_return,"POST");
        }

        prepackage.success_call_back = function (id, max_id) {
            popup.success("新建成功");
            setTimeout(function () {
                popup.close("asyncbox_success");
            }, 2000);
            if ($("input[name=flag]").val() == 1)
                top.window.location.href = 'Transitwms/prepackage/print_batch_order?id=' + id + '&packing_id=' + max_id + '&flag=' + $("input[name=flag]").val();
            else
                top.window.location.href = 'Transitwms/prepackage/print_batch_order?id=' + id + '&packing_id=' + max_id;
        }

        /*prepackage.error_call_back = function () {
            popup.error("新建失败");
            setTimeout(function () {
                popup.close("asyncbox_error");
            }, 2000);
        }

        prepackage.show_check_quality_details = function () {
            prepackage.get_check_quality_details();
        }

        prepackage.show_prepackage_details = function () {
            prepackage.get_prepackage_details();
        }*/

        prepackage.reset_page = function () {
            top.window.location.href = top.window.location.href;
        }

        prepackage.ajax_request = function (data, url, method,type) {
            $.ajax({
                type: type,

                url: url,
                //JSON.stringify()
                data: {data: JSON.stringify(data)},

                dataType: "json",

                success: method
            });
        }

        prepackage.not_tax_table_result = function (data) {
            if(data.status==0){
                layer.msg(data.info);
                return;
            }
            $("#addtr").html(data);
        }

        prepackage.tax_table_result     = function (data) {
            if(data.status==0){
                layer.msg(data.info);
                return;
            }
            $("#addtr3").html(data);
        }

        prepackage.get_plan_detail      = function (data){

            if(data.flag == 1)
            {
                popup.error(data.info);
                return ;
            }
            $(".detail_content").html(data);
        }

        prepackage.get_create_package_box_return= function(data){
            if (data.flag == -1) {
                popup.error("新建失败,请重新提交");
                setTimeout(function () {
                    popup.close("asyncbox_error");
                }, 2000);
                return;
            } else if (data.flag == 0) {
                popup.success("新建成功");
                setTimeout(function () {
                }, 2000);
                window.location.href = '__URL__/package_box_index';
            } else if(data.flag == 1)
            {
                popup.error(data.info);
                setTimeout(function () {
                    popup.close("asyncbox_error");
                }, 2000);
                return;
            }else
            {
                popup.error(data.info);
            }

            /*if (data.status) {
                prepackage.success_call_back(data.status, data.id);
            } else {
                prepackage.error_call_back();
            }*/
        }

        return prepackage;
    }
};
//var sku_list="<?php echo json_encode($sku)?>";

//根据标识符flag来判断是正常装箱或是特殊装箱
$("input[name=recieve_detail_id]").keydown(function (e) {
    if (e.keyCode == 13) {
        if ($("input[name=flag]").val() == 1)               //创建特殊唛头
        {
            Prepackage.createNew().show_prepackage_details();
        } else {
            Prepackage.createNew().show_check_quality_details();
        }
    }
});

$(document).on("click", ".is_not_tax", function(){
    if ($("input[name=not_tax_package_quantity]").val() == '') {
        popup.success("请输入箱数");
        return;
    }

    if($("input[name=sku_list_not_tax]").val() == undefined)
    {
        layer.msg('请输入平台计划单', {offset: 250});return ;
    }else if($("input[name=sku_list_not_tax]").val() == ''){
        layer.msg('平台计划单不存在该种类的sku', {offset: 250});return ;
    }

    Prepackage.createNew().ajax_request({'data': $("input[name=not_tax_package_quantity]").val()},
            'Inbound/Inboundshipmentplan/create_prepackage_table', Prepackage.createNew().not_tax_table_result,"GET");
});


$(document).on("click", ".is_tax", function(){
    if ($("input[name=tax_package_quantity]").val() == '') {
        popup.success("请输入箱数");
        return;
    }

    if($("input[name=sku_list_tax]").val() == undefined)
    {
        layer.msg('请输入平台计划单', {offset: 250});return ;
    }else if($("input[name=sku_list_tax]").val() == ''){
        layer.msg('平台计划单不存在该种类的sku', {offset: 250});return ;
    }

    Prepackage.createNew().ajax_request({'data': $("input[name=tax_package_quantity]").val()},
            'Inbound/Inboundshipmentplan/create_prepackage_table?flag=1', Prepackage.createNew().tax_table_result,"GET");
});


$(".submit").click(function () {
    if ($("input[name=sku]").val() == '') {
        layer.msg('请确认质检单是否存在', {offset: 250});
        return;
    } else {
        Prepackage.createNew().submit_page_data();
    }
});

$(".jsSearchBtn").click(function(){
    Prepackage.createNew().ajax_request({'shipmentid': $("input[name=shipmentid]").val()},
            'Inbound/Inboundshipmentplan/package_box_index', Prepackage.createNew().get_plan_detail,"GET");
});
</script>